package com.example.administrator.myapplication;

import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;

import java.net.URI;
import java.sql.SQLData;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2018/1/2.
 */

public class ActivityManager {
    private static ActivityManager instance;
    private List<Activity> list;
    private static Uri uri; //= Uri.parse(/sdcard/demo.mp3);


    public static ActivityManager getInstance() {
        if(instance == null)
        {
            instance = new ActivityManager();
        }
        return instance;
    }

    //添加Acticity进列表
    public void addActivity(Activity av){
        if(list == null) {
            list = new ArrayList<Activity>();
            if (av != null)
                list.add(av);
        }

    }

    public static Uri getUri() {
        return uri;
    }

    public static void setUri(Uri uri) {
        ActivityManager.uri = uri;
    }

    public void exitAllProgress(){
        for(int i = 0;i<list.size();i++){
            Activity av = list.get(i);
            av.finish();
        }
    }

    public void saveNote(SQLiteDatabase sqLiteDatabase,String name,String content,String noteId,String time){
        ContentValues values = new ContentValues();
        values.put("noteName",name);
        values.put("noteContent",content);
        values.put("noteTime",time);

        sqLiteDatabase.update("note",values,"noteId = ?",new String[]{noteId});

    }

    public void addNote(SQLiteDatabase sqLiteDatabase,String name,String content,String time){
        ContentValues values = new ContentValues();
        values.put("noteName",name);
        values.put("noteContent",content);
        values.put("noteTime",time);

        sqLiteDatabase.insert("note",null,values);

    }

    public String returnTime() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);

    }

}
